package cn.com.util;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class HourGap
{
  public static String dateDiff(String startTime, String endTime, String format)
  {
    SimpleDateFormat sd = new SimpleDateFormat(format);
    
    long nd = 86400000L;
    
    long nh = 3600000L;
    
    long nm = 60000L;
    
    long ns = 1000L;
    
    long day = 0L;
    long hour = 0L;
    long min = 0L;
    long sec = 0L;
    try
    {
      long diff = sd.parse(endTime).getTime() - sd.parse(startTime).getTime();
      
      day = diff / nd;
      
      hour = diff % nd / nh;
      
      min = diff % nd % nh / nm;
      
      sec = diff % nd % nh % nm / ns;
    }
    catch (ParseException e)
    {
      e.printStackTrace();
      return "0";
    }
    long diff;
    return "����������" + day + "��" + hour + "����" + min + "����" + sec + "����";
  }
  
  public static boolean getTimeDiff(String pBeginTime, String pEndTime)
    throws Exception
  {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm");
    Long beginL = Long.valueOf(format.parse(pBeginTime).getTime());
    Long endL = Long.valueOf(format.parse(pEndTime).getTime());
    Long day = Long.valueOf((endL.longValue() - beginL.longValue()) / 86400000L);
    Long hour = Long.valueOf((endL.longValue() - beginL.longValue()) % 86400000L / 3600000L);
    Long min = Long.valueOf((endL.longValue() - beginL.longValue()) % 86400000L % 3600000L / 60000L);
    if ((day.longValue() > 0.0D) || (hour.longValue() > 0.0D) || (min.longValue() > 30L)) {
      return true;
    }
    return false;
  }
  
  //eTime比sTime大minute分钟以上
  public static boolean getBoolTimeDiff(String sTime, String eTime,Long minute)
		    throws Exception
		  {
		    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm");
		    Long beginL = Long.valueOf(format.parse(sTime).getTime());
		    Long endL = Long.valueOf(format.parse(eTime).getTime());
		    Long day = Long.valueOf((endL.longValue() - beginL.longValue()) / 86400000L);
		    Long hour = Long.valueOf((endL.longValue() - beginL.longValue()) % 86400000L / 3600000L);
		    Long min = Long.valueOf((endL.longValue() - beginL.longValue()) % 86400000L % 3600000L / 60000L);
		    if ((day.longValue() > 0.0D) || (hour.longValue() > 0.0D) || (min.longValue() > minute)) {
		      return true;
		    }
		    return false;
		  }
  
  public static boolean getTimeDiff(Date pBeginTime, Date pEndTime)
    throws Exception
  {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm");
    String begin = format.format(getTime(pBeginTime));
    String end = format.format(getTime(pEndTime));
    Long beginL = Long.valueOf(format.parse(begin).getTime());
    Long endL = Long.valueOf(format.parse(end).getTime());
    Long day = Long.valueOf((endL.longValue() - beginL.longValue()) / 86400000L);
    if (day.longValue() > 1.0D) {
      return true;
    }
    return false;
  }
  
  public static Date getTime(Date date)
  {
    try
    {
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm");
      return format.parse(format.format(date));
    }
    catch (ParseException e) {}
    return null;
  }
  
  public static String getTimetoString(Date date)
  {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm");
    String d = format.format(date);
    return d;
  }
  
  public static String getTimeFromTimestamp(long timestamp)
  {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String date = sdf.format(new Date(timestamp * 1000L));
    return date;
  }
  
  public static long getExpireTimestamp(long timestamp)
  {
    return timestamp + 86400L;
  }
  
  public static void main(String[] args)
  {
			System.out.println( getMonth("2016-02-03 00:00:00"));
  }
  
  public static long getBirthdayInterval(String birthday)
  {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    Calendar cal = Calendar.getInstance();
    int yearNow = cal.get(1);
    try
    {
      cal.setTime(formatter.parse(birthday));
    }
    catch (ParseException e)
    {
      e.printStackTrace();
    }
    int birthyear = cal.get(1);
    while (birthyear < yearNow)
    {
      cal.set(1, cal.get(1) + 1);
      birthyear = cal.get(1);
    }
    Date ed = new Date();
    Date sd = cal.getTime();
    long days = 0L;
    if ((sd.getTime() - ed.getTime()) / 86400000L > 0L)
    {
      days = (sd.getTime() - ed.getTime()) / 86400000L;
    }
    else
    {
      cal.set(1, cal.get(1) + 1);
      sd = cal.getTime();
      days = (sd.getTime() - ed.getTime()) / 86400000L;
    }
    return days;
  }
  
  public static String[] getTodays()
  {
    String[] result = { "", "" };
    Calendar calendar = Calendar.getInstance();
    calendar.set(11, 0);
    calendar.set(12, 0);
    calendar.set(13, 0);
    String s1 = String.valueOf(calendar.getTimeInMillis());
    result[0] = s1.substring(0, 10);
    calendar.set(11, 24);
    calendar.set(12, 0);
    calendar.set(13, 0);
    String s2 = String.valueOf(calendar.getTimeInMillis());
    result[1] = s2.substring(0, 10);
    return result;
  }
  
  public static String[] getWeeks()
  {
    Calendar cal = Calendar.getInstance();
    cal.set(cal.get(1), cal.get(2), 
      cal.get(5), 0, 0, 0);
    cal.set(7, 2);
    String begin = String.valueOf(cal.getTimeInMillis() / 1000L);
    
    cal.set(cal.get(1), cal.get(2), 
      cal.get(5), 0, 0, 0);
    cal.set(7, 2);
    String end = 
      String.valueOf((cal.getTime().getTime() + 604800000L) / 1000L);
    
    return new String[] { begin, end };
  }
  
  public static String getFormat(float d)
  {
    DecimalFormat df = new DecimalFormat("#.00");
    String result = df.format(d);
    if (result.indexOf(".") == 0) {
      result = "0" + result;
    }
    return result;
  }
  
  public static String change(String date)
  {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String date2 = "";
    try
    {
      date2 = sdf.format(sdf.parse(date));
    }
    catch (ParseException e)
    {
      e.printStackTrace();
    }
    return date2;
  }
  
  public static String getNowTime()
  {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String date = sdf.format(new Date());
    return date;
  }
  
  public static String getExpireTime(String now, String index)
    throws ParseException
  {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    Long beginL = Long.valueOf(format.parse(now).getTime() / 1000L);
    Long ExpireTime = Long.valueOf(beginL.longValue() + Integer.parseInt(index));
    String result = getTimeFromTimestamp(ExpireTime.longValue());
    return result;
  }
  
  public static String get15days()
    throws ParseException
  {
    long time = Long.parseLong(String.valueOf(new Date().getTime())
      .substring(0, 10));
    time += 1296000L;
    
    return getTimeFromTimestamp(time);
  }
  
  public static String getNMonths(String now, int months)
    throws ParseException
  {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    Date nowDate = sdf.parse(now);
    Calendar cal = Calendar.getInstance();
    cal.setTime(nowDate);
    int month = cal.get(2);
    cal.set(2, month + months);
    String dateStr = sdf.format(cal.getTime());
    return dateStr;
  }
  
  public static String getNNMonths(String now, int months)
		    throws ParseException
		  {
		    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		    Date nowDate = sdf.parse(now);
		    Calendar cal = Calendar.getInstance();
		    cal.setTime(nowDate);
		    int month = cal.get(2);
		    cal.set(2, month + months);
		    String dateStr = sdf.format(cal.getTime());
		    return dateStr;
		  }
  
  public static String getNDays(int days)
    throws ParseException
  {
    long time = Long.parseLong(String.valueOf(new Date().getTime())
      .substring(0, 10));
    time += 86400 * days;
    
    return getTimeFromTimestamp(time);
  }
  
  public static int getExpireTime(String beginT)
    throws ParseException
  {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    Long beginL = Long.valueOf(format.parse(beginT).getTime() / 1000L);
    long time = Long.parseLong(String.valueOf(new Date().getTime())
      .substring(0, 10));
    
    int result = (int)(time - beginL.longValue());
    
    return result;
  }
  
  public static int getMonth(String beginT)
  {
	  int interval = 0;
	  try
	  {
		  interval = getExpireTime(beginT);
	  }
	  catch (ParseException e)
	  {
		  e.printStackTrace();
	  }
				  if (interval / 2592000 > 0)
				  {
					  return interval / 2592000 ;
				  }
				  return 0;
  }
  public static String intervalTime(String beginT)
  {
    int interval = 0;
    try
    {
      interval = getExpireTime(beginT);
    }
    catch (ParseException e)
    {
      e.printStackTrace();
    }
    if (interval / 60 > 0)
    {
      if (interval / 3600 > 0)
      {
        if (interval / 86400 > 0)
        {
          if (interval / 2592000 > 0)
          {
            if (interval / 31536000 > 0) {
              return interval / 31536000 + "年";
            }
            return interval / 2592000 + "月";
          }
          return interval / 86400 + "天";
        }
        return interval / 3600 + "小时";
      }
      return interval / 60 + "分";
    }
    return interval + "秒";
  }
  /**
   * 得到年龄 XX岁XX个月XX天
   * @param date1 生日  2016—02—29
   * @param date2 今天 2016—03—04
   * @return
   * @throws ParseException
   */
  public static String getMonthSpace(String date1, String date2)
          throws ParseException {

      int result = 0;

      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

      int BIRTHDAY_YEAR=Integer.parseInt(date1.substring(0, 4));
      int BIRTHDAY_MONTH=Integer.parseInt(date1.substring(5, 7));
      int BIRTHDAY_DAY=Integer.parseInt(date1.substring(8, 10));
      int NOW_YEAR=Integer.parseInt(date2.substring(0, 4));
      int NOW_MONTH=Integer.parseInt(date2.substring(5, 7));
      int NOW_DAY=Integer.parseInt(date2.substring(8, 10));
      int DAYS_OF_MONTH=31;
      
      Calendar c1 = Calendar.getInstance();
      Calendar c2 = Calendar.getInstance();

      c1.setTime(sdf.parse(date1));
      c2.setTime(sdf.parse(date2));
      
      if (c2.after(c2)) {
    	  throw new IllegalArgumentException(
    	  "Can't be born in the future");
    	  }

      int year = c2.get(Calendar.YEAR) - c1.get(Calendar.YEAR);
      int month = c2.get(Calendar.MONTH) - c1.get(Calendar.MONTH);
      int day = c2.get(Calendar.DAY_OF_MONTH) - c1.get(Calendar.DAY_OF_MONTH);
      
      // 同年
      if(year==0){
    	  
    	  // 同月
    	  if(month==0){
    		  
    		  return day+"天";
    		
    		  // 不同月
    	  }else{
    		  
    		  // 如果day>0 返回月加天 如果等于0 返回月 如果小于0返回月-1+相隔天数
    		  if(day>0){
    			  
    			  return month+"个月"+day+"天";
    			  
    		  }else if(day==0){
    			  
    			  return month+"个月";
    			  
    		  }else if(day<0){
    			
    				  // 上个月是几月
    				  int before_month=NOW_MONTH-1;
    				  
    				 if(before_month==4||before_month==6||before_month==9||before_month==11){
    					 DAYS_OF_MONTH=30;
    					 
    				 }else if(before_month==2){
    					 
    				  if ((NOW_YEAR % 400 == 0) || ((NOW_YEAR % 4 == 0) && (NOW_YEAR % 100 != 0))) {
    					  DAYS_OF_MONTH = 29;
    			        }else{
    			        	 DAYS_OF_MONTH = 28;
    			        }
    			  }
    				 // 如果month=1 返回天数 
    				 day=DAYS_OF_MONTH-BIRTHDAY_DAY+NOW_DAY;
    				 if(month==1){
    					 return day+"天";
    				 }else{
    					 month=month-1;
    					 return month+"个月"+day+"天";
    				 }
    		  }
    		  
    	  }
    	  
      }else{
    	
    	  if(month>0){
    		  
    		  if(day>0){
    			   
    			  return year+"岁"+month+"个月"+day+"天";
    			 
    			  
    		  }else if(day==0){
    			  
    			  return year+"岁"+month+"个月";
    			  
    		  }else if(day<0){
    			  
				  // 上个月是几月
				  int before_month=NOW_MONTH-1;
				  
				 if(before_month==4||before_month==6||before_month==9||before_month==11){
					 DAYS_OF_MONTH=30;
					 
				 }else if(before_month==2){
					 
				  if ((NOW_YEAR % 400 == 0) || ((NOW_YEAR % 4 == 0) && (NOW_YEAR % 100 != 0))) {
					  DAYS_OF_MONTH = 29;
			        }else{
			        	 DAYS_OF_MONTH = 28;
			        }
			  }
				 
				 // 如果month=1 返回天数 
				 day=DAYS_OF_MONTH-BIRTHDAY_DAY+NOW_DAY;
				 if(month==1){
					 return year+"岁"+day+"天";
				 }else{
					 month=month-1;
					 return year+"岁"+month+"个月"+day+"天";
				 }
		  
    		  }
    		  
    	  }else if(month==0){

    		  if(day>0){
    			   
    			  return year+"岁"+day+"天";
    			 
    			  
    		  }else if(day==0){
    			  
    			  return year+"岁";
    			  
    		  }else if(day<0){
    			  
				  // 上个月是几月
				  int before_month=NOW_MONTH-1;
				  
				 if(before_month==4||before_month==6||before_month==9||before_month==11){
					 DAYS_OF_MONTH=30;
					 
				 }else if(before_month==2){
					 
				  if ((NOW_YEAR % 400 == 0) || ((NOW_YEAR % 4 == 0) && (NOW_YEAR % 100 != 0))) {
					  DAYS_OF_MONTH = 29;
			        }else{
			        	 DAYS_OF_MONTH = 28;
			        }
			  }
				 
				 // 如果month=1 返回天数 
				 day=DAYS_OF_MONTH-BIRTHDAY_DAY+NOW_DAY;
				 if(year==1){
					 
					 return "11个月"+day+"天";
				 }else{
					 year=year-1;
					 return year+"岁"+11+"个月"+day+"天";
				 }
		  
    		  }
    		  
    	  }else if(month<0){

    		  if(day>0){
    			   month=12-BIRTHDAY_MONTH+NOW_MONTH;
    			  if(year==1){
    				return  month+"个月"+day+"天";
    			  }else{
    				  year=year-1;
    				  return year+"岁"+month+"个月"+day+"天";
    			  }
    			  
    			 
    			  
    		  }else if(day==0){
    			  
    			  month=12-BIRTHDAY_MONTH+NOW_MONTH;
    			  if(year==1){
    				return  month+"个月";
    			  }else{
    				  year=year-1;
    				  return year+"岁"+month+"个月";
    			  }
    			  
    		  }else if(day<0){
    			  
				  // 上个月是几月
				  int before_month=NOW_MONTH-1;
				  
				 if(before_month==4||before_month==6||before_month==9||before_month==11){
					 DAYS_OF_MONTH=30;
					 
				 }else if(before_month==2){
					 
				  if ((NOW_YEAR % 400 == 0) || ((NOW_YEAR % 4 == 0) && (NOW_YEAR % 100 != 0))) {
					  DAYS_OF_MONTH = 29;
			        }else{
			        	 DAYS_OF_MONTH = 28;
			        }
			  }
				 
				 // 如果month=1 返回天数 
				 day=DAYS_OF_MONTH-BIRTHDAY_DAY+NOW_DAY-1;
				 
				 month=12-BIRTHDAY_MONTH+NOW_MONTH-1;
   			  if(year==1){
   				return  month+"个月"+day+"天";
   			  }else{
   				  year=year-1;
   				  return year+"岁"+month+"个月"+day+"天";
   			  }
				 
    		  }
    		  
    	  
    	  }
    	  
      }
      return "";


  }
  /**
   * 得到年龄 XX个月
   * @param date1 生日  2016—02—29
   * @param date2 今天 2016—03—04
   * @return
   * @throws ParseException
   */
  public static int getMonth(String date1, String date2)
		  throws ParseException {
	  
	  
	  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	  
	  int BIRTHDAY_YEAR=Integer.parseInt(date1.substring(0, 4));
	  int BIRTHDAY_MONTH=Integer.parseInt(date1.substring(5, 7));
	  int BIRTHDAY_DAY=Integer.parseInt(date1.substring(8, 10));
	  int NOW_YEAR=Integer.parseInt(date2.substring(0, 4));
	  int NOW_MONTH=Integer.parseInt(date2.substring(5, 7));
	  int NOW_DAY=Integer.parseInt(date2.substring(8, 10));
	  int DAYS_OF_MONTH=31;
	  
	  Calendar c1 = Calendar.getInstance();
	  Calendar c2 = Calendar.getInstance();
	  
	  c1.setTime(sdf.parse(date1));
	  c2.setTime(sdf.parse(date2));
	  
	  if (c2.after(c2)) {
		  throw new IllegalArgumentException(
				  "Can't be born in the future");
	  }
	  
	  int year = c2.get(Calendar.YEAR) - c1.get(Calendar.YEAR);
	  int month = c2.get(Calendar.MONTH) - c1.get(Calendar.MONTH);
	  int day = c2.get(Calendar.DAY_OF_MONTH) - c1.get(Calendar.DAY_OF_MONTH);
	  
	  // 同年
	  if(year==0){
		  
		  // 同月
		  if(month==0){
			  
			  return 0;
			  
			  // 不同月
		  }else{
			  
			  // 如果day>0 返回月加天 如果等于0 返回月 如果小于0返回月-1+相隔天数
			  if(day>0){
				  
				  return month;
				  
			  }else if(day==0){
				  
				  return month;
				  
			  }else if(day<0){
				  
				  // 上个月是几月
				  int before_month=NOW_MONTH-1;
				  
				  if(before_month==4||before_month==6||before_month==9||before_month==11){
					  DAYS_OF_MONTH=30;
					  
				  }else if(before_month==2){
					  
					  if ((NOW_YEAR % 400 == 0) || ((NOW_YEAR % 4 == 0) && (NOW_YEAR % 100 != 0))) {
						  DAYS_OF_MONTH = 29;
					  }else{
						  DAYS_OF_MONTH = 28;
					  }
				  }
				  // 如果month=1 返回天数 
						  day=DAYS_OF_MONTH-BIRTHDAY_DAY+NOW_DAY;
						  if(month==1){
							  return 0;
						  }else{
							  month=month-1;
							  return month;
						  }
			  }
			  
		  }
		  
	  }else{
		  
		  if(month>0){
			  
			  if(day>0){
				  
				  return year*12+month;
				  
				  
			  }else if(day==0){
				  
				  return year*12+month;
				  
			  }else if(day<0){
				  
				  // 上个月是几月
				  int before_month=NOW_MONTH-1;
				  
				  if(before_month==4||before_month==6||before_month==9||before_month==11){
					  DAYS_OF_MONTH=30;
					  
				  }else if(before_month==2){
					  
					  if ((NOW_YEAR % 400 == 0) || ((NOW_YEAR % 4 == 0) && (NOW_YEAR % 100 != 0))) {
						  DAYS_OF_MONTH = 29;
					  }else{
						  DAYS_OF_MONTH = 28;
					  }
				  }
				  
				  // 如果month=1 返回天数 
				  day=DAYS_OF_MONTH-BIRTHDAY_DAY+NOW_DAY;
				  if(month==1){
					  return year*12;
				  }else{
					  month=month-1;
					  return year*12 +month;
				  }
				  
			  }
			  
		  }else if(month==0){
			  
			  if(day>0){
				  
				  return year*12;
				  
				  
			  }else if(day==0){
				  
				  return year*12;
				  
			  }else if(day<0){
				  
				  // 上个月是几月
				  int before_month=NOW_MONTH-1;
				  
				  if(before_month==4||before_month==6||before_month==9||before_month==11){
					  DAYS_OF_MONTH=30;
					  
				  }else if(before_month==2){
					  
					  if ((NOW_YEAR % 400 == 0) || ((NOW_YEAR % 4 == 0) && (NOW_YEAR % 100 != 0))) {
						  DAYS_OF_MONTH = 29;
					  }else{
						  DAYS_OF_MONTH = 28;
					  }
				  }
				  
				  // 如果month=1 返回天数 
				  day=DAYS_OF_MONTH-BIRTHDAY_DAY+NOW_DAY;
				  if(year==1){
					  
					  return 11;
				  }else{
					  year=year-1;
					  return year*12+11;
				  }
				  
			  }
			  
		  }else if(month<0){
			  
			  if(day>0){
				  month=12-BIRTHDAY_MONTH+NOW_MONTH;
				  if(year==1){
					  return  month;
				  }else{
					  year=year-1;
					  return year*12+month;
				  }
				  
				  
				  
			  }else if(day==0){
				  
				  month=12-BIRTHDAY_MONTH+NOW_MONTH;
				  if(year==1){
					  return  month;
				  }else{
					  year=year-1;
					  return year*12+month;
				  }
				  
			  }else if(day<0){
				  
				  // 上个月是几月
				  int before_month=NOW_MONTH-1;
				  
				  if(before_month==4||before_month==6||before_month==9||before_month==11){
					  DAYS_OF_MONTH=30;
					  
				  }else if(before_month==2){
					  
					  if ((NOW_YEAR % 400 == 0) || ((NOW_YEAR % 4 == 0) && (NOW_YEAR % 100 != 0))) {
						  DAYS_OF_MONTH = 29;
					  }else{
						  DAYS_OF_MONTH = 28;
					  }
				  }
				  
				  // 如果month=1 返回天数 
				  day=DAYS_OF_MONTH-BIRTHDAY_DAY+NOW_DAY-1;
				  
				  month=12-BIRTHDAY_MONTH+NOW_MONTH-1;
				  if(year==1){
					  return  month;
				  }else{
					  year=year-1;
					  return year*12+month;
				  }
				  
			  }
			  
			  
		  }
		  
	  }
	  return 0;
	  
	  
  }
  
  public static Date getyesterdayTimesmorning()
  {
    Calendar cal = Calendar.getInstance();
    cal.add(5, -1);
    cal.set(11, 0);
    cal.set(13, 0);
    cal.set(12, 0);
    cal.set(14, 0);
    return cal.getTime();
  }
  
  public static Date getTimesmorning()
  {
    Calendar cal = Calendar.getInstance();
    cal.set(11, 0);
    cal.set(13, 0);
    cal.set(12, 0);
    cal.set(14, 0);
    return cal.getTime();
  }
  
  public static Date getTimesnight()
  {
    Calendar cal = Calendar.getInstance();
    cal.set(11, 24);
    cal.set(13, 0);
    cal.set(12, 0);
    cal.set(14, 0);
    return cal.getTime();
  }
  
  public static Date getTimesWeekmorning()
  {
    Calendar cal = Calendar.getInstance();
    cal.set(cal.get(1), cal.get(2), 
      cal.get(5), 0, 0, 0);
    cal.set(7, 2);
    return cal.getTime();
  }
  
  public static Date getTimesWeeknight()
  {
    Calendar cal = Calendar.getInstance();
    cal.setTime(getTimesWeekmorning());
    cal.add(7, 7);
    return cal.getTime();
  }
  
  public static Date getTimesMonthmorning()
  {
    Calendar cal = Calendar.getInstance();
    cal.set(cal.get(1), cal.get(2), 
      cal.get(5), 0, 0, 0);
    cal.set(5, 
      cal.getActualMinimum(5));
    return cal.getTime();
  }
  
  public static Date getTimesMonthnight()
  {
    Calendar cal = Calendar.getInstance();
    cal.set(cal.get(1), cal.get(2), 
      cal.get(5), 0, 0, 0);
    cal.set(5, 
      cal.getActualMaximum(5));
    cal.set(11, 24);
    return cal.getTime();
  }
  public static int getWeekOfMonth( String dateString)
  {

	  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	  Date date=new Date();
	try {
		date = sdf.parse(dateString);
	} catch (ParseException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

	  Calendar calendar = Calendar.getInstance();
	  calendar.setTime(date);
	  int weekOfMonth = calendar.get(Calendar.WEEK_OF_MONTH);
	  System.out.println(weekOfMonth);
	  return weekOfMonth;
  }
  
  public static String getNextHour(String oldDate) throws ParseException{
	//  String now = HourGap.getNowTime();
	  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//	String query=now.substring(0, 11)+"00:00:00";
	  Date nowDate = sdf.parse(oldDate);
	    Calendar cal = Calendar.getInstance();
	    cal.setTime(nowDate);
//	    Integer year = cal.get(Calendar.YEAR);
//	    Integer month = cal.get(Calendar.MONTH)+1;
//	    Integer day = cal.get(Calendar.DATE);
	    Integer hour = cal.get(Calendar.HOUR_OF_DAY);
//	    Integer minute = cal.get(Calendar.MINUTE);
//	    Integer second = cal.get(Calendar.SECOND);
//	    System.out.println("year:"+year);
//	    System.out.println("month:"+month);
//	    System.out.println("day:"+day);
//	    System.out.println("hour:"+hour);
//	    System.out.println("minute:"+minute);
//	    System.out.println("second:"+second);
	    cal.set(Calendar.HOUR_OF_DAY, hour + 1);
	    String dateStr = sdf.format(cal.getTime());
	    return dateStr;
  }
  
  public static String getNextMinute(String oldDate,Integer oldMinute) throws ParseException{
//	  String now = HourGap.getNowTime();
	  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	  Date nowDate = sdf.parse(oldDate);
	    Calendar cal = Calendar.getInstance();
	    cal.setTime(nowDate);
//	    Integer year = cal.get(Calendar.YEAR);
//	    Integer month = cal.get(Calendar.MONTH)+1;
//	    Integer day = cal.get(Calendar.DATE);
//	    Integer hour = cal.get(Calendar.HOUR_OF_DAY);
	    Integer minute = cal.get(Calendar.MINUTE);
//	    Integer second = cal.get(Calendar.SECOND);
//	    System.out.println("year:"+year);
//	    System.out.println("month:"+month);
//	    System.out.println("day:"+day);
//	    System.out.println("hour:"+hour);
//	    System.out.println("minute:"+minute);
//	    System.out.println("second:"+second);
	    cal.set(Calendar.MINUTE, minute + oldMinute);
	    String dateStr = sdf.format(cal.getTime());
	    return dateStr;
  }
  
}
